<?php
class Template
{
	private $name;
	private $templatePath;
	
	public function __construct($name)
	{
		$this->name = $name;
		$this->templatePath = $name.'Layout.php';
	}
	
	
	public function initialize()
	{
		ob_start();
		//If a template has particulary initialize code
		switch($this->name)
		{
			case 'application':
				if(!(isset($_SESSION['authenticated']) && is_bool($_SESSION['authenticated']) && $_SESSION['authenticated']))
				{
					header('Location: '.Utils::getUrl(''));
					ob_end_flush();
					exit();
				}
				break;
			case 'main':
				if(isset($_SESSION['authenticated']) && is_bool($_SESSION['authenticated']) && $_SESSION['authenticated'])
				{
					header('Location: '.Utils::getUrl('profile.php'));
					ob_end_flush();
					exit();
				}
				break;
		}
	}
	
	public function createPage($title)
	{
		$pageMainContent = ob_get_contents();  
		ob_end_clean();
		$pageTitle = $title;
		include($this->templatePath);
                die();
	}
}
?>